//
//  DLMachineChartsTC.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/28.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLMachineChartsTC.h"
#import "DLMachineModel.h"
#import "DLTimeSharingView.h"
#import "DLKLineView.h"
#import "DLPieChartView.h"
#import "DLHistogramView.h"

@interface DLMachineChartsTC()

@property (nonatomic, strong) DLTimeSharingView *timeSharingView;

@property (nonatomic, strong) DLKLineView *kLineView;

@property (nonatomic, strong) DLPieChartView *pieChartView;

@property (nonatomic, strong) DLHistogramView *histogramView;


@end


@implementation DLMachineChartsTC

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self layoutsubControls];
        self.backgroundColor = kDLMachineTableAndCellBgColor;
//        self.backgroundColor = kColorRGB(240, 240, 240);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
- (void) layoutsubControls {
    
    
    
    
    DLTimeSharingView *timeSharingView = [[DLTimeSharingView alloc] initWithFrame:CGRectMake(kMachineChartsBgViewLeftMargin, 10, kScreenWidth - kMachineChartsBgViewLeftMargin *2, kMachineChartsHeight - 20)];
    [self.contentView addSubview:timeSharingView];
    self.timeSharingView = timeSharingView;
    timeSharingView.hidden = YES;

    
    DLKLineView *kLineView = [[DLKLineView alloc] initWithFrame:timeSharingView.frame];
    [self.contentView addSubview:kLineView];
    self.kLineView = kLineView;
    kLineView.hidden = YES;

    
    DLPieChartView *pieChartView = [[DLPieChartView alloc] initWithFrame:timeSharingView.frame];
    [self.contentView addSubview:pieChartView];
    self.pieChartView = pieChartView;
    pieChartView.hidden = YES;

    
    DLHistogramView *histogramView = [[DLHistogramView alloc] initWithFrame:timeSharingView.frame];
    [self.contentView addSubview:histogramView];
    self.histogramView = histogramView;
    histogramView.hidden = YES;
    
}
- (void) setChartsModel:(DLMachineModel *)chartsModel {
    _chartsModel = chartsModel;
    
    switch (chartsModel.msgType) {
        case SocketMsgType_kLineChart:
        {
            NSLog(@"k线");
            self.timeSharingView.hidden = YES;
            self.pieChartView.hidden = YES;
            self.histogramView.hidden = YES;
            self.kLineView.hidden = NO;
            
            self.kLineView.dataSourceDic = chartsModel.resultDic;
        }
            break;
        case SocketMsgType_pieChart:
        {
            NSLog(@"饼图");
            self.timeSharingView.hidden = YES;
            self.pieChartView.hidden = NO;
            self.histogramView.hidden = YES;
            self.kLineView.hidden = YES;
            
            self.pieChartView.dataSourceDic = chartsModel.resultDic;
        }
            break;
        case SocketMsgType_histogram:
        {
            NSLog(@"柱状图");
            self.timeSharingView.hidden = YES;
            self.pieChartView.hidden = YES;
            self.histogramView.hidden = NO;
            self.kLineView.hidden = YES;
            
            self.histogramView.dataSourceDic = chartsModel.resultDic;
        }
            break;
        case SocketMsgType_timeSharing:
        {
            NSLog(@"分时图（折线图）");
            self.timeSharingView.hidden = NO;
            self.pieChartView.hidden = YES;
            self.histogramView.hidden = YES;
            self.kLineView.hidden = YES;
            
            self.timeSharingView.dataSourceDic = chartsModel.resultDic;
        }
            break;
            
        default:
            break;
    }
    
    
    
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
